/**
 * $version:  0.1 
 * $Date: 2011-01-21 
 *
 * Copyright (C) 2010-2011 Jawa Software. All rights reserved.
 *
 */

package org.jawa.learning.model;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.jawa.core.cache.CacheSizes;
import org.jawa.core.cache.Cacheable;
import org.jawa.core.cache.CannotCalculateSizeException;

/**
 * 用户信息 .
 * @author Yak
 */
public class User implements Cacheable {
	private static final long serialVersionUID = -8557878791634494271L;

	private Long id;

	private Long brId;

	private String username;

	private String userType;

	private String fullName;

	private String sex;

	private String enabled;

	private String password;

	private String passwordHint;

	private String picture;

	private String email;

	private String phoneNumber;

	private String registerTime;

	private String lastLoginTime;

	private String remark;

    private Set<Role> roles = new HashSet<Role>();
    
	/**
	 * This method was generated by MyBatis Generator.
	 * This method returns the value of the database column app_user.id
	 *
	 * @return the value of app_user.id
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public Long getId() {
		return id;
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method sets the value of the database column app_user.id
	 *
	 * @param id the value for app_user.id
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method returns the value of the database column app_user.br_id
	 *
	 * @return the value of app_user.br_id
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public Long getBrId() {
		return brId;
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method sets the value of the database column app_user.br_id
	 *
	 * @param brId the value for app_user.br_id
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public void setBrId(Long brId) {
		this.brId = brId;
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method returns the value of the database column app_user.username
	 *
	 * @return the value of app_user.username
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public String getUsername() {
		return username;
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method sets the value of the database column app_user.username
	 *
	 * @param username the value for app_user.username
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public void setUsername(String username) {
		this.username = username == null ? null : username.trim();
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method returns the value of the database column app_user.user_type
	 *
	 * @return the value of app_user.user_type
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public String getUserType() {
		return userType;
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method sets the value of the database column app_user.user_type
	 *
	 * @param userType the value for app_user.user_type
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public void setUserType(String userType) {
		this.userType = userType == null ? null : userType.trim();
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method returns the value of the database column app_user.full_name
	 *
	 * @return the value of app_user.full_name
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public String getFullName() {
		return fullName;
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method sets the value of the database column app_user.full_name
	 *
	 * @param fullName the value for app_user.full_name
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public void setFullName(String fullName) {
		this.fullName = fullName == null ? null : fullName.trim();
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method returns the value of the database column app_user.sex
	 *
	 * @return the value of app_user.sex
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public String getSex() {
		return sex;
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method sets the value of the database column app_user.sex
	 *
	 * @param sex the value for app_user.sex
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public void setSex(String sex) {
		this.sex = sex == null ? null : sex.trim();
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method returns the value of the database column app_user.enabled
	 *
	 * @return the value of app_user.enabled
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public String getEnabled() {
		return enabled;
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method sets the value of the database column app_user.enabled
	 *
	 * @param enabled the value for app_user.enabled
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public void setEnabled(String enabled) {
		this.enabled = enabled == null ? null : enabled.trim();
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method returns the value of the database column app_user.password
	 *
	 * @return the value of app_user.password
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method sets the value of the database column app_user.password
	 *
	 * @param password the value for app_user.password
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public void setPassword(String password) {
		this.password = password == null ? null : password.trim();
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method returns the value of the database column app_user.password_hint
	 *
	 * @return the value of app_user.password_hint
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public String getPasswordHint() {
		return passwordHint;
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method sets the value of the database column app_user.password_hint
	 *
	 * @param passwordHint the value for app_user.password_hint
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public void setPasswordHint(String passwordHint) {
		this.passwordHint = passwordHint == null ? null : passwordHint.trim();
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method returns the value of the database column app_user.picture
	 *
	 * @return the value of app_user.picture
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public String getPicture() {
		return picture;
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method sets the value of the database column app_user.picture
	 *
	 * @param picture the value for app_user.picture
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public void setPicture(String picture) {
		this.picture = picture == null ? null : picture.trim();
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method returns the value of the database column app_user.email
	 *
	 * @return the value of app_user.email
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method sets the value of the database column app_user.email
	 *
	 * @param email the value for app_user.email
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public void setEmail(String email) {
		this.email = email == null ? null : email.trim();
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method returns the value of the database column app_user.phone_number
	 *
	 * @return the value of app_user.phone_number
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public String getPhoneNumber() {
		return phoneNumber;
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method sets the value of the database column app_user.phone_number
	 *
	 * @param phoneNumber the value for app_user.phone_number
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber == null ? null : phoneNumber.trim();
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method returns the value of the database column app_user.register_time
	 *
	 * @return the value of app_user.register_time
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public String getRegisterTime() {
		return registerTime;
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method sets the value of the database column app_user.register_time
	 *
	 * @param registerTime the value for app_user.register_time
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public void setRegisterTime(String registerTime) {
		this.registerTime = registerTime == null ? null : registerTime.trim();
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method returns the value of the database column app_user.last_login_time
	 *
	 * @return the value of app_user.last_login_time
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public String getLastLoginTime() {
		return lastLoginTime;
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method sets the value of the database column app_user.last_login_time
	 *
	 * @param lastLoginTime the value for app_user.last_login_time
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public void setLastLoginTime(String lastLoginTime) {
		this.lastLoginTime = lastLoginTime == null ? null : lastLoginTime.trim();
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method returns the value of the database column app_user.remark
	 *
	 * @return the value of app_user.remark
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public String getRemark() {
		return remark;
	}

	/**
	 * This method was generated by MyBatis Generator.
	 * This method sets the value of the database column app_user.remark
	 *
	 * @param remark the value for app_user.remark
	 *
	 * @mbggenerated Wed Sep 12 15:50:33 CST 2012
	 */
	public void setRemark(String remark) {
		this.remark = remark == null ? null : remark.trim();
	}
	
	
	public Set<Role> getRoles() {
		return roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}

	@Override
	public String toString() {
		return username;
	}

	public int getCachedSize() throws CannotCalculateSizeException {
		int size = 0;
		size += CacheSizes.sizeOfObject(); // overhead of object
		size += CacheSizes.sizeOfLong(); // User Id
		size += CacheSizes.sizeOfLong(); // User Branch Id
		size += CacheSizes.sizeOfString(username); // loginNo
		size += CacheSizes.sizeOfString(userType); // User Type
		size += CacheSizes.sizeOfString(fullName); // User Name
		size += CacheSizes.sizeOfString(sex); // User Sex
		size += CacheSizes.sizeOfString(enabled); // User enabled
		size += CacheSizes.sizeOfString(password); // User Password
		size += CacheSizes.sizeOfString(picture); // User Picture
		size += CacheSizes.sizeOfString(email); // User Email
		size += CacheSizes.sizeOfString(phoneNumber); // User Phone
		size += CacheSizes.sizeOfString(registerTime); // User Regedit Time
		size += CacheSizes.sizeOfString(lastLoginTime); // User Last Login Time
		size += CacheSizes.sizeOfString(remark); // remark
		for (Iterator<Role> iterator = roles.iterator(); iterator.hasNext();) {
			Role role = iterator.next();
			size += role.getCachedSize();// roles
		}
		return size;
	}

}